package com.gt.web.srv.web.api.command;

import cn.hutool.core.util.IdcardUtil;
import com.gt.web.api.exception.BusinessException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotEmpty;

/**
 * 注册绑定入参
 *
 * @author Yu Chaohua
 * @date 2024/5/18 23:14
 */
@Data
@ApiModel(description = "登录后绑定身份证入参")
public class RegisterPeopleCardCommand {

    @ApiModelProperty(value = "身份证号")
    @NotEmpty(message = "身份证号")
    private String headCard;

    public void check() {
        if (!IdcardUtil.isValidCard(this.headCard) && !isAlphanumeric(this.headCard)) {
            throw new BusinessException(3000,"身份证号有误");
        }
    }

    public boolean isAlphanumeric(String input) {
        return input.matches("[A-Za-z0-9]+");
    }

    // public static void main(String[] args) {
    //     String test = "Test123a";
    //     System.out.println(isAlphanumeric(test)); // 输出结果取决于test是否只包含字母和数字
    // }
}
